﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ViewAndEditAllCuts : System.Web.UI.Page
{
    private System.Data.DataSet AllCuts;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            LoadData();
    }
    public void LoadData()
    {
        AllCuts = MusicLine.MusicLineController.GetAllCuts();
        uxAllCutsDataList.DataSource = AllCuts.Tables[0];
        uxAllCutsDataList.DataBind();
    }
    protected void uxAllCutsDataList_EditCommand(object source, DataListCommandEventArgs e)
    {
        uxAllCutsDataList.EditItemIndex = e.Item.ItemIndex;
        LoadData();
    }
    protected void uxAllCutsDataList_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        // TODO: Fix by adding the AlbumId (to uniquely identify the cut)
        MusicLine.MusicLineController.UpdateCut(int.Parse(((HiddenField)e.Item.FindControl("uxAlbumIdTextBox")).Value), int.Parse(((HiddenField)e.Item.FindControl("uxCutNumberTextBox")).Value), ((TextBox)e.Item.FindControl("uxTitleTextBox")).Text, int.Parse(((TextBox)e.Item.FindControl("uxLengthInSecondsTextBox")).Text));
        uxAllCutsDataList.EditItemIndex = -1;
        LoadData();
        ((Label)uxAllCutsDataList.Controls[e.Item.ItemIndex].FindControl("uxSuccessMessageLabel")).Text = "******* Update Successful *********";
    }
    protected void uxAllCutsDataList_CancelCommand(object source, DataListCommandEventArgs e)
    {
        uxAllCutsDataList.EditItemIndex = 1;
        LoadData();
    }
}
